from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-23 14:13:07.357465
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 23, Sep, 2022
Time: 14:13:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.4979
Nobs: 788.000 HQIC: -50.8262
Log likelihood: 10133.2 FPE: 6.87722e-23
AIC: -51.0313 Det(Omega_mle): 6.13936e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299395 0.053811 5.564 0.000
L1.Burgenland 0.108224 0.035843 3.019 0.003
L1.Kärnten -0.106521 0.019064 -5.588 0.000
L1.Niederösterreich 0.207650 0.074936 2.771 0.006
L1.Oberösterreich 0.104529 0.072046 1.451 0.147
L1.Salzburg 0.252611 0.038267 6.601 0.000
L1.Steiermark 0.038034 0.050010 0.761 0.447
L1.Tirol 0.106190 0.040534 2.620 0.009
L1.Vorarlberg -0.059475 0.034875 -1.705 0.088
L1.Wien 0.053709 0.064446 0.833 0.405
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061175 0.111601 0.548 0.584
L1.Burgenland -0.034036 0.074336 -0.458 0.647
L1.Kärnten 0.048038 0.039537 1.215 0.224
L1.Niederösterreich -0.173719 0.155415 -1.118 0.264
L1.Oberösterreich 0.388222 0.149421 2.598 0.009
L1.Salzburg 0.287482 0.079365 3.622 0.000
L1.Steiermark 0.107358 0.103719 1.035 0.301
L1.Tirol 0.312750 0.084066 3.720 0.000
L1.Vorarlberg 0.026505 0.072328 0.366 0.714
L1.Wien -0.016975 0.133658 -0.127 0.899
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191647 0.027634 6.935 0.000
L1.Burgenland 0.089536 0.018407 4.864 0.000
L1.Kärnten -0.008325 0.009790 -0.850 0.395
L1.Niederösterreich 0.263085 0.038483 6.836 0.000
L1.Oberösterreich 0.127703 0.036999 3.452 0.001
L1.Salzburg 0.047240 0.019652 2.404 0.016
L1.Steiermark 0.018222 0.025682 0.710 0.478
L1.Tirol 0.093526 0.020816 4.493 0.000
L1.Vorarlberg 0.058957 0.017910 3.292 0.001
L1.Wien 0.119384 0.033096 3.607 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108805 0.028297 3.845 0.000
L1.Burgenland 0.044564 0.018849 2.364 0.018
L1.Kärnten -0.015793 0.010025 -1.575 0.115
L1.Niederösterreich 0.192711 0.039406 4.890 0.000
L1.Oberösterreich 0.293913 0.037887 7.758 0.000
L1.Salzburg 0.114119 0.020124 5.671 0.000
L1.Steiermark 0.101840 0.026299 3.872 0.000
L1.Tirol 0.115039 0.021316 5.397 0.000
L1.Vorarlberg 0.071317 0.018339 3.889 0.000
L1.Wien -0.026808 0.033890 -0.791 0.429
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132001 0.051230 2.577 0.010
L1.Burgenland -0.052345 0.034124 -1.534 0.125
L1.Kärnten -0.040173 0.018150 -2.213 0.027
L1.Niederösterreich 0.171238 0.071343 2.400 0.016
L1.Oberösterreich 0.137160 0.068591 2.000 0.046
L1.Salzburg 0.286075 0.036432 7.852 0.000
L1.Steiermark 0.036154 0.047612 0.759 0.448
L1.Tirol 0.163216 0.038590 4.229 0.000
L1.Vorarlberg 0.102573 0.033202 3.089 0.002
L1.Wien 0.066239 0.061356 1.080 0.280
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058996 0.040697 1.450 0.147
L1.Burgenland 0.038260 0.027108 1.411 0.158
L1.Kärnten 0.051091 0.014418 3.544 0.000
L1.Niederösterreich 0.222889 0.056674 3.933 0.000
L1.Oberösterreich 0.283806 0.054488 5.209 0.000
L1.Salzburg 0.049288 0.028941 1.703 0.089
L1.Steiermark -0.004546 0.037822 -0.120 0.904
L1.Tirol 0.148285 0.030656 4.837 0.000
L1.Vorarlberg 0.072777 0.026375 2.759 0.006
L1.Wien 0.080127 0.048740 1.644 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180819 0.048643 3.717 0.000
L1.Burgenland -0.006510 0.032401 -0.201 0.841
L1.Kärnten -0.061127 0.017233 -3.547 0.000
L1.Niederösterreich -0.083085 0.067740 -1.227 0.220
L1.Oberösterreich 0.193717 0.065128 2.974 0.003
L1.Salzburg 0.057041 0.034593 1.649 0.099
L1.Steiermark 0.232010 0.045208 5.132 0.000
L1.Tirol 0.493560 0.036642 13.470 0.000
L1.Vorarlberg 0.048334 0.031526 1.533 0.125
L1.Wien -0.052482 0.058257 -0.901 0.368
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164502 0.055861 2.945 0.003
L1.Burgenland -0.010589 0.037209 -0.285 0.776
L1.Kärnten 0.066565 0.019790 3.364 0.001
L1.Niederösterreich 0.200127 0.077792 2.573 0.010
L1.Oberösterreich -0.063904 0.074792 -0.854 0.393
L1.Salzburg 0.212839 0.039726 5.358 0.000
L1.Steiermark 0.116723 0.051916 2.248 0.025
L1.Tirol 0.074600 0.042079 1.773 0.076
L1.Vorarlberg 0.123816 0.036204 3.420 0.001
L1.Wien 0.117318 0.066902 1.754 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359634 0.032356 11.115 0.000
L1.Burgenland 0.006164 0.021552 0.286 0.775
L1.Kärnten -0.023179 0.011463 -2.022 0.043
L1.Niederösterreich 0.219988 0.045059 4.882 0.000
L1.Oberösterreich 0.178962 0.043321 4.131 0.000
L1.Salzburg 0.045575 0.023010 1.981 0.048
L1.Steiermark -0.016433 0.030071 -0.546 0.585
L1.Tirol 0.106597 0.024373 4.374 0.000
L1.Vorarlberg 0.073029 0.020970 3.483 0.000
L1.Wien 0.050731 0.038752 1.309 0.190
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040938 0.150962 0.191507 0.156258 0.125482 0.112147 0.066295 0.223399
Kärnten 0.040938 1.000000 -0.002928 0.129407 0.041671 0.095505 0.430369 -0.053374 0.101499
Niederösterreich 0.150962 -0.002928 1.000000 0.336224 0.151938 0.300343 0.107676 0.182921 0.324153
Oberösterreich 0.191507 0.129407 0.336224 1.000000 0.230899 0.332065 0.172056 0.170595 0.262553
Salzburg 0.156258 0.041671 0.151938 0.230899 1.000000 0.146850 0.123359 0.148146 0.132745
Steiermark 0.125482 0.095505 0.300343 0.332065 0.146850 1.000000 0.153051 0.139897 0.079205
Tirol 0.112147 0.430369 0.107676 0.172056 0.123359 0.153051 1.000000 0.114538 0.152364
Vorarlberg 0.066295 -0.053374 0.182921 0.170595 0.148146 0.139897 0.114538 1.000000 0.004097
Wien 0.223399 0.101499 0.324153 0.262553 0.132745 0.079205 0.152364 0.004097 1.000000